﻿using API_Service.BizLogic.WIPControl;
using Nancy;
using Newtonsoft.Json;

namespace API_Service.Module
{
    public class WIPKeypartsModule : BaseAPIModule
    {
        private WIPKeypartsService wipKPS = new WIPKeypartsService();

        public WIPKeypartsModule() : base("/wipkps")
        {
            Get["/"] = _ => Response.AsJson("WIP kps数据查询");

            //获取原材BOX信息
            Get["GetWIPKPSList", "/wipkps/{sn}"] = p =>
            {
                string sn = (string)p.sn;

                return Response.AsJson(wipKPS.GetSNWIPKPSList(sn));
            };

            Get["/wipkps/validate"] = _ =>
            {
                string model = Request.Query["MODEL"];

                return Response.AsJson(wipKPS.ValidateWIPKPSExist(model));
            };

            Post["/wipkps/getkpslist"] = _ =>
            {
                string model = Request.Query["MODEL"];

                return Response.AsJson(wipKPS.QueryWipKpsListInfo(model));
            };

            //update wip kps
            Post["/update"] = _ =>
            {
                //string model = (string)Request.Form["MODEL"];
                string sn = (string)Request.Form["sn"];
                string kpsn = (string)Request.Form["kpsn"];
                string line = (string)Request.Form["line"];
                string group = (string)Request.Form["group"];
                string emp = (string)Request.Form["emp"];
                ExecutionResult<dynamic> result;
                result = new ExecutionResult<dynamic>();
                //wip keyparts 捡料

                result = this.wipKPS.PickUpSNWIPKeyparts(new { sn = sn, kpsn = kpsn, line = line, group = group, emp = emp });
                //result = this.wipKPS.PickUpSNWIPKeyparts(model);

                return Response.AsJson(result);
            };
        }
    }
}